const states = require("./States.js")
/**
 * 封装响应对象
 */
const response = {
    /**
     * 返回正确的响应对象{code:200,msg:msg,data:data}
     * @param {Object} data 需要响应给前端的数据
     * @param {String} msg 需要响应给前端的消息
     * @returns 
     */
    success: (data, msg) => {
        return {
            code: states.SUCCESS,
            msg: msg || "success",
            data: data
        }
    },
    /**
     * 返回错误的响应对象{code:code,msg:errMsg}
     * @param {String} errMsg 
     * @param {Number} code 
     * @returns 
     */
    error: (errMsg, code = states.ERROR) => {
        return {
            code: code,
            msg: errMsg || "error"
        }
    }
}

module.exports = response